package com.tikeyc.flutterandroid;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.tikeyc.flutterandroid.custom.MyFlutterActivity;

import io.flutter.embedding.android.FlutterView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 默认启动方式
        LinearLayout linearLayout = findViewById(R.id.my_button_super);
        Button button1 = linearLayout.findViewById(R.id.my_button1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = MyFlutterActivity.createDefaultIntent(MainActivity.this);
                startActivity(intent);
            }
        });
        // initialRoute初始化路由
        Button button2 = linearLayout.findViewById(R.id.my_button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = MyFlutterActivity
                        .withNewEngine()
                        .initialRoute("/")
                        .build(MainActivity.this);
                startActivity(intent);
            }
        });

        // 使用缓存的FlutterEngine，明显提高启动性能
        Button button3 = linearLayout.findViewById(R.id.my_button3);
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = MyFlutterActivity
                        .withCachedEngine(MyApplication.MY_ENGINE_ID)
                        .build(MainActivity.this);
                startActivity(intent);
            }
        });

        // 打开FlutterFragment
        Button button4 = linearLayout.findViewById(R.id.my_button4);
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, MyFragmentActivity.class);
                startActivity(intent);
            }
        });

        //
        FlutterView flutterView = new FlutterView(this);

    }
}